// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/flag_definitions/flags.h>

// Used in pollux/common/memory/Memory.cpp

TURBO_FLAG(int32_t,
    pollux_memory_num_shared_leaf_pools,
    32,
    "Number of shared leaf memory pools per process");

TURBO_FLAG(bool,
    pollux_time_allocations,
    false,
    "Record time and volume for large allocation/free");

// Used in common/base/PolluxException.cpp
TURBO_FLAG(bool,
    pollux_exception_user_stacktrace_enabled,
    false,
    "Enable the stacktrace for user type of PolluxException");

TURBO_FLAG(bool,
    pollux_exception_system_stacktrace_enabled,
    true,
    "Enable the stacktrace for system type of PolluxException");

TURBO_FLAG(int32_t,
    pollux_exception_user_stacktrace_rate_limit_ms,
    0, // effectively turns off rate-limiting
    "Min time interval in milliseconds between stack traces captured in"
    " user type of PolluxException; off when set to 0 (the default)");

TURBO_FLAG(int32_t,
    pollux_exception_system_stacktrace_rate_limit_ms,
    0, // effectively turns off rate-limiting
    "Min time interval in milliseconds between stack traces captured in"
    " system type of PolluxException; off when set to 0 (the default)");

// Used in common/base/ProcessBase.cpp

TURBO_FLAG(bool,avx2, true, "Enables use of AVX2 when available");

TURBO_FLAG(bool,bmi2, true, "Enables use of BMI2 when available");

// Used in exec/Expr.cpp

TURBO_FLAG(std::string,
    pollux_save_input_on_expression_any_failure_path,
    "",
    "Enable saving input vector and expression SQL on any failure during "
    "expression evaluation. Specifies the directory to use for storing the "
    "vectors and expression SQL strings.");

TURBO_FLAG(std::string,
    pollux_save_input_on_expression_system_failure_path,
    "",
    "Enable saving input vector and expression SQL on system failure during "
    "expression evaluation. Specifies the directory to use for storing the "
    "vectors and expression SQL strings. This flag is ignored if "
    "pollux_save_input_on_expression_any_failure_path is set.");

TURBO_FLAG(bool,
    force_eval_simplified,
    false,
    "Whether to overwrite queryCtx and force the "
    "use of simplified expression evaluation path.");

TURBO_FLAG(bool,
    pollux_experimental_save_input_on_fatal_signal,
    false,
    "This is an experimental flag only to be used for debugging "
    "purposes. If set to true, serializes the input vector data and "
    "all the SQL expressions in the ExprSet that is currently "
    "executing, whenever a fatal signal is encountered. Enabling "
    "this flag makes the signal handler async signal unsafe, so it "
    "should only be used for debugging purposes. The vector and SQLs "
    "are serialized to files in directories specified by either "
    "'pollux_save_input_on_expression_any_failure_path' or "
    "'pollux_save_input_on_expression_system_failure_path'");

// TODO: deprecate this once all the memory leak issues have been fixed in
// existing meta internal use cases.
TURBO_FLAG(bool,
    pollux_memory_leak_check_enabled,
    false,
    "If true, check fails on any memory leaks in memory pool and memory manager");

TURBO_FLAG(bool,
    pollux_memory_pool_debug_enabled,
    false,
    "If true, 'MemoryPool' will be running in debug mode to track the allocation and free call sites to detect the source of memory leak for testing purpose");

// TODO: deprecate this after solves all the use cases that can cause
// significant performance regression by memory usage tracking.
TURBO_FLAG(bool,
    pollux_enable_memory_usage_track_in_default_memory_pool,
    false,
    "If true, enable memory usage tracking in the default memory pool");

TURBO_FLAG(bool,
    pollux_suppress_memory_capacity_exceeding_error_message,
    false,
    "If true, suppress the verbose error message in memory capacity exceeded "
    "exception. This is only used by test to control the test error output size");

TURBO_FLAG(bool,pollux_memory_use_hugepages, true, "Use explicit huge pages");

TURBO_FLAG(int32_t,
    cache_prefetch_min_pct,
    80,
    "Minimum percentage of actual uses over references to a column for prefetching. No prefetch if > 100");

TURBO_FLAG(bool,pollux_ssd_odirect, true, "Use O_DIRECT for SSD cache IO");

TURBO_FLAG(bool,
    pollux_ssd_verify_write,
    false,
    "Read back data after writing to SSD");

// Used in /connectors/tpch
TURBO_FLAG(int32_t,
    pollux_tpch_text_pool_size_mb,
    300,
    "TPC-H DBGen text pool size in MB");
TURBO_FLAG(bool,
    pollux_memory_pool_capacity_transfer_across_tasks,
    false,
    "Whether allow to memory capacity transfer between memory pools from different tasks, which might happen in use case like Spark-Gluten")
;

TURBO_FLAG(std::string,profiler_tmp_dir, "/tmp", "Writable temp for perf.data");

TURBO_FLAG(int32_t,
    profiler_check_interval_seconds,
    60,
    "Frequency of checking CPU load and turning profiling on/off");

TURBO_FLAG(int32_t,
    profiler_min_cpu_pct,
    200,
    "Minimum CPU percent to justify profile. 100 is one core busy");

TURBO_FLAG(int32_t,
    profiler_min_sample_seconds,
    60,
    "Minimum amount of time at above minimum load to justify producing a result file");

TURBO_FLAG(int32_t,
    profiler_max_sample_seconds,
    300,
    "Number of seconds before switching to new file");

TURBO_FLAG(std::string,profiler_perf_flags, "", "Extra flags for Linux perf");

TURBO_FLAG(bool,experimental_enable_legacy_cast,
    false,
    "Experimental feature flag for backward compatibility with previous output"
    " format of type conversions used for casting. This is a temporary solution"
    " that aims to facilitate a seamless transition for users who rely on the"
    " legacy behavior and hence can change in the future.");

TURBO_FLAG(bool, wsVRLoad, false, "Use WS VRead API to load");
